#include "userCfgDefault.h"
#include "userProfileLut.h"
#include "bsp_spi.h"

//RC8088_RWCfg_st RC8088_RW;
// RC8088_RegCfg_st *rc8088_regCfg;//=(RC8088_RegCfg_st *)(RC8088_REG_ADDR);
// STRUCT_RC8088_USERCFG *rc8088_userCfg;//=(STRUCT_RC8088_USERCFG *)(RC8088_USERCFG_ADDR);
// STRUCT_PROFILEMEM_ADDR *profMemAddr;

STRUCT_USR_CONFIG_CONST g_rf_far_userconfig_default;
STRUCT_USR_CONFIG_CONST g_rf_near_userconfig_default;
STRUCT_USR_CONFIG_CONST g_rf_far_userconfig;
STRUCT_USR_CONFIG_CONST g_rf_near_userconfig;
uint8_t g_profile_mem[8192];

//64,128,256,512,1024,2048
uint32_t readFFT_PT(uint32_t ptIn){
    uint32_t rtn=0;
    switch(ptIn){
        case 64:rtn=2;break;
        case 128:rtn=3;break;
        case 256:rtn=4;break;
        case 512:rtn=5;break;
        case 1024:rtn=6;break;
        case 2048:rtn=7;break; 
    }
    return rtn;
}
void RC8088_ProfileMemAddrInit(STRUCT_PROFILEMEM_ADDR *m_profMemAddr){
	// printf("g_profile_mem is %p.\n", (void *)g_profile_mem);
	m_profMemAddr->profileAddr     =(uint32_t)g_profile_mem;                               					 //192*28=5376Byte
	// printf("profMemAddr->profileAddr is %u.\n", profMemAddr->profileAddr); 
	m_profMemAddr->rampMemAddr     =m_profMemAddr->profileAddr+5376;                     //240Byte
	m_profMemAddr->startFreqMemAddr=m_profMemAddr->rampMemAddr+12*MAX_PROFILEMEM_NUM;    //80Byte
	m_profMemAddr->adcRmaMemAddr   =m_profMemAddr->startFreqMemAddr+4*MAX_PROFILEMEM_NUM;//40Byte
	m_profMemAddr->txEnMemAddr     =m_profMemAddr->adcRmaMemAddr+2*MAX_PROFILEMEM_NUM;   //20Byte
	m_profMemAddr->bpmMemAddr      =m_profMemAddr->txEnMemAddr+MAX_PROFILEMEM_NUM;       //2048Byte
	m_profMemAddr->tx0PhaseMemAddr =m_profMemAddr->bpmMemAddr+MAX_BPM_NUM;               //20Byte
	m_profMemAddr->tx1PhaseMemAddr =m_profMemAddr->tx0PhaseMemAddr+MAX_PROFILEMEM_NUM;   //20Byte
	m_profMemAddr->tx2PhaseMemAddr =m_profMemAddr->tx1PhaseMemAddr+MAX_PROFILEMEM_NUM;   //20Byte
	m_profMemAddr->tx3PhaseMemAddr =m_profMemAddr->tx2PhaseMemAddr+MAX_PROFILEMEM_NUM;   //20Byte
	m_profMemAddr->tx4PhaseMemAddr =m_profMemAddr->tx3PhaseMemAddr+MAX_PROFILEMEM_NUM;   //20Byte
	m_profMemAddr->tx5PhaseMemAddr =m_profMemAddr->tx4PhaseMemAddr+MAX_PROFILEMEM_NUM;   //20Byte
	m_profMemAddr->tx6PhaseMemAddr =m_profMemAddr->tx5PhaseMemAddr+MAX_PROFILEMEM_NUM;   //20Byte
	m_profMemAddr->tx7PhaseMemAddr =m_profMemAddr->tx6PhaseMemAddr+MAX_PROFILEMEM_NUM;   //20Byte
 	m_profMemAddr->testMemAddr     =m_profMemAddr->tx7PhaseMemAddr+MAX_PROFILEMEM_NUM;   
//	printf("regAddr=%08X,profileMemAddr=%08X,userCfgAddr=%08X\n",RC8088_REG_ADDR,RC8088_PROFILE_ADDR,RC8088_USERCFG_ADDR);
	printf("STRUCT:reg=%d,profileLut=%d,userCfg=%d\n",sizeof(RC8088_RegCfg_st),sizeof(STRUCT_PROFILELUT),sizeof(STRUCT_RC8088_USERCFG));
}

void RC8088_userCfgDefault(RC8088_RWCfg_st *pCfg, STRUCT_RC8088_USERCFG *rc8088_userCfg,STRUCT_PROFILEMEM_ADDR *m_profMemAddr){

	uint32_t rampRst=0;
	/****************************************************************************InitCfg*/
//	rc8088_userCfg->numFrame=1;
	// rc8088_userCfg->BspEndian=RC8088_L_END;
	rc8088_userCfg->cpEn = 0;
	rc8088_userCfg->cqEn = 0;
	rc8088_userCfg->dataEn = 1;
	rc8088_userCfg->cq2_limit = 0.5f;
	rc8088_userCfg->numCqPT = 64;
	rc8088_userCfg->dc_removal = 0;
	rc8088_userCfg->win_sym = 1;
	rc8088_userCfg->adc_dsize=2;
	rc8088_userCfg->zero_out_bypass = 1;
//	rc8088_userCfg->numEdma=rc8088_userCfg->numPT*rc8088_userCfg->numRX*rc8088_userCfg->numBytes;
	rc8088_userCfg->numMipiChirp=rc8088_userCfg->numPrepChirp;
//	if(rc8088_userCfg->cpEn){
//		rc8088_userCfg->numMipi=rc8088_userCfg->numEdma+32;
//	}else{
//		rc8088_userCfg->numMipi=rc8088_userCfg->numEdma;
//	}	
	/****************************************************************************userCommon*/
	rc8088_userCfg->userCommon.gpio_sta=0;
	rc8088_userCfg->userCommon.gpio_oe=0;//0xF
	rc8088_userCfg->userCommon.clk_out_mode=0; //1:outEn  0:shutdown
	rc8088_userCfg->userCommon.adc_dmux=0;
	rc8088_userCfg->userCommon.dclk_div=0;
	/*****************************************************************************analog*/
	//CFG0
	rc8088_userCfg->userAnalog.cfg0_UFT0 = 0x00; //BIT31:28
	rc8088_userCfg->userAnalog.enmipi    = 0x03; //BIT27:26
	rc8088_userCfg->userAnalog.enadc     = 0xFF; //BIT25:18
	rc8088_userCfg->userAnalog.enlorx    = 0x03; //BIT17:16
	rc8088_userCfg->userAnalog.enrxrf    = 0x0F; //BIT15:12
	rc8088_userCfg->userAnalog.enrxbb    = 0xFF; //BIT11:4
	rc8088_userCfg->userAnalog.enlotx    = 0x03; //BIT3:2
	rc8088_userCfg->userAnalog.enlofan   = 0x01; //BIT1
	rc8088_userCfg->userAnalog.enpll     = 0x01; //BIT0
	//CFG1
//	if(rc8088_userCfg->userProfMan.profile_man_vld){
//		if(rc8088_userCfg->FreqStart+rc8088_userCfg->Bandwidth<=78){  //0x000056ED
//			rc8088_userCfg->userAnalog.ct_acccur  = 0;      //BIT31:28
//			rc8088_userCfg->userAnalog.cfg1_UFT1  = 0;      //BIT27:15
//			rc8088_userCfg->userAnalog.ct_vcoband = 0;      //BIT14:12
//			rc8088_userCfg->userAnalog.cfg1_UFT0  = 0x1BB;  //BIT11:2  1B9
//			rc8088_userCfg->userAnalog.envco      = 1;      //BIT1:0   2		
//		}else{                                                         //0x0FFF06E2
//			rc8088_userCfg->userAnalog.ct_acccur  = 0;      //BIT31:28
//			rc8088_userCfg->userAnalog.cfg1_UFT1  = 0x1FFC; //BIT27:15
//			rc8088_userCfg->userAnalog.ct_vcoband = 0;      //BIT14:12
//			rc8088_userCfg->userAnalog.cfg1_UFT0  = 0x1B9;  //BIT11:2  1B9
//			rc8088_userCfg->userAnalog.envco      = 2;      //BIT1:0   2		
//		}
//	}else{                                              //0x0FFF06E2
//			rc8088_userCfg->userAnalog.ct_acccur  = 0;      //BIT31:28
//			rc8088_userCfg->userAnalog.cfg1_UFT1  = 0x1FFC; //BIT27:15
//			rc8088_userCfg->userAnalog.ct_vcoband = 0;      //BIT14:12
//			rc8088_userCfg->userAnalog.cfg1_UFT0  = 0x1B9;  //BIT11:2  1B9
//			rc8088_userCfg->userAnalog.envco      = 2;      //BIT1:0   2		
//	}

	//CFG2
	rc8088_userCfg->userAnalog.cfg2_NC        = 0; //BIT31:24
	rc8088_userCfg->userAnalog.cfg2_UFT3      = 7; //BIT23:14  7:950K*256   5:868K*256  3:770K*256
	rc8088_userCfg->userAnalog.SYNC_source    = 0; //BIT13
	rc8088_userCfg->userAnalog.CLK40M_source  = 0; //BIT12
	rc8088_userCfg->userAnalog.RXBBTSTsigFreq = 0; //BIT11
	rc8088_userCfg->userAnalog.RXBBTSTsig     = 0; //BIT10
	rc8088_userCfg->userAnalog.GPADC3         = 0; //BIT9
	rc8088_userCfg->userAnalog.cfg2_UFT2      = 0; //BIT8
	rc8088_userCfg->userAnalog.GPADC2         = 0; //BIT7
	rc8088_userCfg->userAnalog.cfg2_UFT1      = 0; //BIT6
	rc8088_userCfg->userAnalog.GPADC1         = 0; //BIT5
	rc8088_userCfg->userAnalog.cfg2_UFT0      = 0; //BIT4:0
	//CFG3
	rc8088_userCfg->userAnalog.cfg3_UFT0       = 0xEC;//BIT31:24   old : 0xCC
	rc8088_userCfg->userAnalog.TX8PowerManual = rc8088_userCfg->txAntPower; //BIT23:21
	rc8088_userCfg->userAnalog.TX7PowerManual = rc8088_userCfg->txAntPower; //BIT20:18
	rc8088_userCfg->userAnalog.TX6PowerManual = rc8088_userCfg->txAntPower; //BIT17:15
	rc8088_userCfg->userAnalog.TX5PowerManual = rc8088_userCfg->txAntPower; //BIT14:12
	rc8088_userCfg->userAnalog.TX4PowerManual = rc8088_userCfg->txAntPower; //BIT11:9
	rc8088_userCfg->userAnalog.TX3PowerManual = rc8088_userCfg->txAntPower; //BIT8:6
	rc8088_userCfg->userAnalog.TX2PowerManual = rc8088_userCfg->txAntPower; //BIT5:3
	rc8088_userCfg->userAnalog.TX1PowerManual = rc8088_userCfg->txAntPower; //BIT2:0
	//CFG4
	rc8088_userCfg->userAnalog.TX8PowerAdj = 0; //BIT31:28
	rc8088_userCfg->userAnalog.TX7PowerAdj = 0; //BIT27;24
	rc8088_userCfg->userAnalog.TX6PowerAdj = 0; //BIT23;20
	rc8088_userCfg->userAnalog.TX5PowerAdj = 0; //BIT19;16
	rc8088_userCfg->userAnalog.TX4PowerAdj = 0; //BIT15;12
	rc8088_userCfg->userAnalog.TX3PowerAdj = 0; //BIT11;8
	rc8088_userCfg->userAnalog.TX2PowerAdj = 0; //BIT7;4
	rc8088_userCfg->userAnalog.TX1PowerAdj = 0; //BIT3;0
	//CFG5
	rc8088_userCfg->userAnalog.cfg5_UFT1 = 6;                         //BIT31:12
	rc8088_userCfg->userAnalog.HPsta1 = rc8088_userCfg->HPF0;         //BIT11:10
	rc8088_userCfg->userAnalog.HPsta2 = rc8088_userCfg->HPF1;         //BIT9:8
	rc8088_userCfg->userAnalog.cfg5_UFT0 = 2;                         //BIT7:6
	rc8088_userCfg->userAnalog.Gainsta1 = rc8088_userCfg->rxAntGain1; //BIT5:4
	rc8088_userCfg->userAnalog.Gainsta2 = rc8088_userCfg->rxAntGain2; //BIT3:2
	rc8088_userCfg->userAnalog.Gainsta3 = rc8088_userCfg->rxAntGain3; //BIT1:0
	//CFG6
	rc8088_userCfg->userAnalog.cfg6_UFT0 = 0; //BIT31:0
	//CFG7
	rc8088_userCfg->userAnalog.cfg7_UFT0=0x025F0C00;//BIT31:0   40M:0x025F1CFB   BIT3:0, PLL1_N-8   BIT7:4 FREF_N-8   50M:0x025F1C56     OLD :0x025F1C00
	rc8088_userCfg->userAnalog.cfg7_UFT0=rc8088_userCfg->userAnalog.cfg7_UFT0|((FREF_N_NUM-8)<<4)|(PLL1_N_NUM-8);
	//CFG8
	rc8088_userCfg->userAnalog.cfg8_UFT0=0x01080FFF;//BIT31:0   old:0xF1001FFE
	//CFG9
	rc8088_userCfg->userAnalog.cfg9_UFT1 = 0x00;   //BIT31:26  //0X00
	rc8088_userCfg->userAnalog.losel     = 0x80;   //BIT25:16
    rc8088_userCfg->userAnalog.cfg9_UFT0 = 0xC188; //BIT15:0    fref_N: bit10=1:(8-23)->0x0580      bit10=0:(16-47)->0x0180   old:C188

	//CFG10
	rc8088_userCfg->userAnalog.cfg10_UFT0=0x00486210;//BIT31:0
	//CFG11
	rc8088_userCfg->userAnalog.cfg11_UFT0=0x57D10009;//BIT31:0   old:0x4FF1100A
	//CFG12 
	rc8088_userCfg->userAnalog.cfg12_UFT0=0x00000000;//BIT31:0  0x00010000:padEn
	//CFG13
	rc8088_userCfg->userAnalog.cfg13_UFT0=0x00A6655A;//BIT31:0  0x00E5760A:47.5M  0x00A5760A:54.2M      0x0065760A:63.3M    0x0025760A:76M    
	//CFG14
	rc8088_userCfg->userAnalog.cfg14_UFT0=0x00000000;//BIT31:0
	//CFG15
	rc8088_userCfg->userAnalog.cfg15_UFT1=0x0D0;//BIT31:20  0xD0:maxgain   0xD3:mingain
	rc8088_userCfg->userAnalog.RX_Gain0 = rc8088_userCfg->rxAntGain0;//BIT19:16
	rc8088_userCfg->userAnalog.cfg15_UFT0=0x4F81;//BIT15:0
	//CFG16
	rc8088_userCfg->userAnalog.cfg16_UFT0=0x0C00000A;//BIT31:0   old 0x0C00000A   old:0x0000001A
	//CFG17
	rc8088_userCfg->userAnalog.cfg17_UFT0=0x00000000;//BIT31:0
	//CFG18
	rc8088_userCfg->userAnalog.cfg18_UFT0=0x5C500000;//BIT31:0  old 0xFC500000  old2:0x00000003
	//CFG19
	rc8088_userCfg->userAnalog.cfg19_UFT0=0;//BIT31:0
	//CFG20
	HAL_RC8088_CalcMipiRate(rc8088_userCfg);//postDiv,mDiv,fractionDiv
	//CFG21
	rc8088_userCfg->userAnalog.cfg21_UFT0=0x00009780;//BIT31:0
	//CFG22
	rc8088_userCfg->userAnalog.mipidphy_cfg0_ch3=rc8088_userCfg->mipiCfg.DelayCH[3]+(1<<4);//BIT31:27 BIT26:24
	rc8088_userCfg->userAnalog.mipidphy_cfg0_ch2=rc8088_userCfg->mipiCfg.DelayCH[2]+(1<<4);//BIT23:19 BIT18:16
	rc8088_userCfg->userAnalog.mipidphy_cfg0_ch1=rc8088_userCfg->mipiCfg.DelayCH[1]+(1<<4);//BIT15:11 BIT10:8
	rc8088_userCfg->userAnalog.mipidphy_cfg0_ch0=rc8088_userCfg->mipiCfg.DelayCH[0]+(1<<4);//BIT7:3   BIT2:0	
	//CFG23
	rc8088_userCfg->userAnalog.mipidphy_cfg0_ch7=rc8088_userCfg->mipiCfg.DelayCH[7]+(1<<4);//BIT31:27
	rc8088_userCfg->userAnalog.mipidphy_cfg0_ch6=rc8088_userCfg->mipiCfg.DelayCH[6]+(1<<4);//BIT23:19
	rc8088_userCfg->userAnalog.mipidphy_cfg0_ch5=rc8088_userCfg->mipiCfg.DelayCH[5]+(1<<4);//BIT15:11
	rc8088_userCfg->userAnalog.mipidphy_cfg0_ch4=rc8088_userCfg->mipiCfg.DelayCH[4]+(1<<4);//BIT7:3	
	//CFG24
	rc8088_userCfg->userAnalog.mipidphy_cfg0=0xFFFF;//31:16
	rc8088_userCfg->userAnalog.mipidphy_cfg0_chck2=rc8088_userCfg->mipiCfg.DelayCK[1]+(9<<4);//BIT15:8
	rc8088_userCfg->userAnalog.mipidphy_cfg0_chck =rc8088_userCfg->mipiCfg.DelayCK[0]+(9<<4);//BIT7:0
	//CFG25
	rc8088_userCfg->userAnalog.cfg25_UFT0=0x03000F00;//BIT31:0  old:0x03000F00

	/**************************************************************************************profileMan*/
	if(rc8088_userCfg->userProfMan.profile_man_vld){//manual
		//CFG1
		rampRst=HAL_RC8088_CalcRampReg(0,rc8088_userCfg->basicCfg.sweepTimeA);
		rc8088_userCfg->userProfMan.ramp_a_inc =rampRst&0xFFFF;
		rc8088_userCfg->userProfMan.ramp_a_time=rampRst>>16;
		//CFG2
		rampRst=HAL_RC8088_CalcRampReg(rc8088_userCfg->basicCfg.bandwidth,rc8088_userCfg->basicCfg.sweepTimeB);
		rc8088_userCfg->userProfMan.ramp_b_inc =rampRst&0xFFFF;
		rc8088_userCfg->userProfMan.ramp_b_time=rampRst>>16;
	#if 1
		rc8088_userCfg->userProfMan.ramp_a_inc = rampRst&0xFFFF;
	#endif
		//CFG3
		rampRst=HAL_RC8088_CalcRampReg(-rc8088_userCfg->basicCfg.bandwidth,rc8088_userCfg->basicCfg.sweepTimeC);
		rc8088_userCfg->userProfMan.ramp_c_inc =rampRst&0xFFFF;
		rc8088_userCfg->userProfMan.ramp_c_time=rampRst>>16;	
		//CFG4
		rc8088_userCfg->userProfMan.startFreq=HAL_RC8088_CalcStartFreqReg(rc8088_userCfg->basicCfg.freqStart);
		//CFG5
		rc8088_userCfg->userProfMan.adcRma=rc8088_userCfg->basicCfg.numRma;
		rc8088_userCfg->userProfMan.txEn=rc8088_userCfg->basicCfg.txEn;
		//CFG6
		rc8088_userCfg->userProfMan.tx0Phase=rc8088_userCfg->basicCfg.txPhase[0];
		rc8088_userCfg->userProfMan.tx1Phase=rc8088_userCfg->basicCfg.txPhase[1];
		rc8088_userCfg->userProfMan.tx2Phase=rc8088_userCfg->basicCfg.txPhase[2];
		rc8088_userCfg->userProfMan.tx3Phase=rc8088_userCfg->basicCfg.txPhase[3];
		//CFG7
		rc8088_userCfg->userProfMan.tx4Phase=rc8088_userCfg->basicCfg.txPhase[4];
		rc8088_userCfg->userProfMan.tx5Phase=rc8088_userCfg->basicCfg.txPhase[5];
		rc8088_userCfg->userProfMan.tx6Phase=rc8088_userCfg->basicCfg.txPhase[6];
		rc8088_userCfg->userProfMan.tx7Phase=rc8088_userCfg->basicCfg.txPhase[7];
		//CFG8
		rc8088_userCfg->userProfMan.ramp_sycn_maskA=1;
		rc8088_userCfg->userProfMan.ramp_sycn_maskB=0;
		rc8088_userCfg->userProfMan.ramp_sycn_maskC=0;
		rc8088_userCfg->userProfMan.pll_acc_maskA=0;
		rc8088_userCfg->userProfMan.pll_acc_maskB=0;
		rc8088_userCfg->userProfMan.pll_acc_maskC=0;
		rc8088_userCfg->userProfMan.pa_en_maskA=1;
		rc8088_userCfg->userProfMan.pa_en_maskB=1;
		rc8088_userCfg->userProfMan.pa_en_maskC=1;
		rc8088_userCfg->userProfMan.loopInf=0;                                  //1:loop   0:single
		rc8088_userCfg->userProfMan.loopNum=rc8088_userCfg->basicCfg.numChirp-1;	
		rc8088_userCfg->userSF.sf0_profileLoopInf=0;
		rc8088_userCfg->userSF.sf0_profileLoopNum=1;
		rc8088_userCfg->userSF.sf0_profileNumA=0;
		rc8088_userCfg->userSF.sf0_profileNumB=0;		
		rc8088_userCfg->userSF.sf1_valid=0;
		rc8088_userCfg->userSF.sf1_profileLoopInf=0;
		rc8088_userCfg->userSF.sf1_profileLoopNum=1;
		rc8088_userCfg->userSF.sf1_profileNumA=0;
		rc8088_userCfg->userSF.sf1_profileNumB=0;
		rc8088_userCfg->userSF.sf2_valid=0;
		rc8088_userCfg->userSF.sf2_profileLoopInf=0;
		rc8088_userCfg->userSF.sf2_profileLoopNum=1;
		rc8088_userCfg->userSF.sf2_profileNumA=0;
		rc8088_userCfg->userSF.sf2_profileNumB=0;
		rc8088_userCfg->userSF.sf3_valid=0;
		rc8088_userCfg->userSF.sf3_profileLoopInf=0;
		rc8088_userCfg->userSF.sf3_profileLoopNum=1;
		rc8088_userCfg->userSF.sf3_profileNumA=0;
		rc8088_userCfg->userSF.sf3_profileNumB=0;
	}

	/********************************************************************************SF*/
	rc8088_userCfg->userSF.sf0_interFrameIdleTimeScaleB=0;
	rc8088_userCfg->userSF.sf0_interFrameIdleTimeValueB=0;
	rc8088_userCfg->userSF.sf1_interFrameIdleTimeScaleB=0;
	rc8088_userCfg->userSF.sf1_interFrameIdleTimeValueB=0;	
	rc8088_userCfg->userSF.sf2_interFrameIdleTimeScaleB=0;
	rc8088_userCfg->userSF.sf2_interFrameIdleTimeValueB=0;	
	rc8088_userCfg->userSF.sf3_interFrameIdleTimeScaleB=0;
	rc8088_userCfg->userSF.sf3_interFrameIdleTimeValueB=0;	
	/********************************************************************************prep*/
	uint32_t sampExp   = (uint32_t)floor(get_log2((float)rc8088_userCfg->numPT));
	uint32_t sampFloor = (uint32_t)(1<<sampExp);
	double   sampFac   = round((double)(sampFloor / rc8088_userCfg->numPT) * 4096);
	uint32_t sampFacFix= (uint32_t)sampFac;
	sampFacFix= (sampFacFix==4096) ? 4095 : sampFacFix;
	//cfg0
	rc8088_userCfg->userPrep.samp_pt_rsfb=sampExp;	
	rc8088_userCfg->userPrep.samp_pt_fac=sampFacFix;	
	rc8088_userCfg->userPrep.samp_pt=rc8088_userCfg->numPT-1;
	//cfg1
	if(rc8088_userCfg->fftEn){
		rc8088_userCfg->userPrep.rx_num= (rc8088_userCfg->numRX>4)?7:3;
	}else{
		rc8088_userCfg->userPrep.rx_num= rc8088_userCfg->numRX-1;
	}
	
	rc8088_userCfg->userPrep.pp_num=1-1;
	rc8088_userCfg->userPrep.chirp_rma=1-1;
	rc8088_userCfg->userPrep.chirp_num=rc8088_userCfg->userPrep.chirp_rma+rc8088_userCfg->numPrepChirp-1;
	//cfg2
	rc8088_userCfg->userPrep.cic_sec=rc8088_userCfg->cic_sec;
	rc8088_userCfg->userPrep.down_fac=rc8088_userCfg->downFac;
	rc8088_userCfg->userPrep.adc_lsb=0;
	rc8088_userCfg->userPrep.adc_cat_mode=rc8088_userCfg->fftEn?0:1;
	//add by zzg 20250116_1324
	rc8088_userCfg->userPrep.adc_test_mode=0;
	rc8088_userCfg->userPrep.adc_dsize=rc8088_userCfg->fftEn?2:(2);
	rc8088_userCfg->userPrep.adc_clk_mode=1;
	//cfg3
	rc8088_userCfg->userPrep.rx_antseq7=rc8088_userCfg->rxAntSeq[7];
	rc8088_userCfg->userPrep.rx_antseq6=rc8088_userCfg->rxAntSeq[6];
	rc8088_userCfg->userPrep.rx_antseq5=rc8088_userCfg->rxAntSeq[5];
	rc8088_userCfg->userPrep.rx_antseq4=rc8088_userCfg->rxAntSeq[4];
	rc8088_userCfg->userPrep.rx_antseq3=rc8088_userCfg->rxAntSeq[3];
	rc8088_userCfg->userPrep.rx_antseq2=rc8088_userCfg->rxAntSeq[2];
	rc8088_userCfg->userPrep.rx_antseq1=rc8088_userCfg->rxAntSeq[1];
	rc8088_userCfg->userPrep.rx_antseq0=rc8088_userCfg->rxAntSeq[0];
	//cfg4
	uint32_t cqExp          = (uint32_t)floor(get_log2((float)(rc8088_userCfg->numCqPT)));
	uint32_t cqFloor        = (uint32_t)(1<<cqExp);
	double   cqFac          = round((double)(cqFloor / (rc8088_userCfg->numCqPT)) * 64);
	uint32_t cqFacFix       = (uint32_t)cqFac;
	cqFacFix       = (cqFacFix==64) ? 63 : cqFacFix;
	cqFacFix = 32;
	double cq2_limit_fix  = round(rc8088_userCfg->cq2_limit * 32768);
	rc8088_userCfg->userPrep.cq1_pt_rsfb=cqExp;
	rc8088_userCfg->userPrep.cq1_pt_fac=cqFacFix;
	rc8088_userCfg->userPrep.cq2_timing_limit=(uint32_t )cq2_limit_fix;
	//cfg5
	rc8088_userCfg->userPrep.cq12_ch_num=rc8088_userCfg->fftEn ? ( (rc8088_userCfg->numRX>3)?7:rc8088_userCfg->numRX ) : rc8088_userCfg->numRX;
	rc8088_userCfg->userPrep.cq_pt_num=rc8088_userCfg->numCqPT-1;
	/************************************************************************edma*/
	//cfg0
	rc8088_userCfg->userDMA.trans_mode   =rc8088_userCfg->fftEn;
	rc8088_userCfg->userDMA.interCnt     =rc8088_userCfg->fftEn ? ( (rc8088_userCfg->numRX>4)?1:0 ) : 0;;
	rc8088_userCfg->userDMA.burst_len    =8-1;//96-1;
	rc8088_userCfg->userDMA.prep2rd_dly  =0xF;
	rc8088_userCfg->userDMA.wr2mipi_dly  =0xF;
	rc8088_userCfg->userDMA.entry_e_en   =0;
	rc8088_userCfg->userDMA.entry_d_en   =rc8088_userCfg->cqEn;
	rc8088_userCfg->userDMA.entry_c_en   =rc8088_userCfg->cqEn;
	rc8088_userCfg->userDMA.entry_b_en   =rc8088_userCfg->dataEn;
	rc8088_userCfg->userDMA.entry_a_en   =rc8088_userCfg->cpEn;
	//cfg1       
	if(rc8088_userCfg->fftEn){
        switch(rc8088_userCfg->numRX-1){
                case 0: rc8088_userCfg->userDMA.d_ch_num = 0;break;
                case 1: rc8088_userCfg->userDMA.d_ch_num = 1;break;
                case 2: rc8088_userCfg->userDMA.d_ch_num = 2;break;
                case 3: rc8088_userCfg->userDMA.d_ch_num = 3;break;
                case 5: rc8088_userCfg->userDMA.d_ch_num = 2;break;
                case 7: rc8088_userCfg->userDMA.d_ch_num = 3;break;
        }
	}else{
			rc8088_userCfg->userDMA.d_ch_num                =   3;//0
	}	
	uint32_t  cq12_intra  = (uint32_t)floor(rc8088_userCfg->numPT / (rc8088_userCfg->numCqPT));
						cq12_intra  = (cq12_intra>0) ? cq12_intra-1 : cq12_intra;
						cq12_intra  = (cq12_intra>63)? 63           : cq12_intra;
	rc8088_userCfg->userDMA.d_intraCnt   =cq12_intra;
	rc8088_userCfg->userDMA.c_intraCnt   =5;//5;
	double      data_intra  = .0;
	if(rc8088_userCfg->fftEn){
			data_intra = (rc8088_userCfg->numPT) / 2.0;
	}else{
			switch(rc8088_userCfg->adc_dsize){
					case 0: data_intra = 1.0 * (double)(rc8088_userCfg->numPT) * (double)(rc8088_userCfg->numRX) / 16; break;
					case 1: data_intra = 1.5 * (double)(rc8088_userCfg->numPT) * (double)(rc8088_userCfg->numRX) / 16; break;
					case 2: data_intra = 2.0 * (double)(rc8088_userCfg->numPT) * (double)(rc8088_userCfg->numRX) / 16; break;
			}
	}
	rc8088_userCfg->userDMA.b_intraCnt   = (uint32_t)data_intra-1;
	//cfg2              
	rc8088_userCfg->userDMA.e_intraCnt   =(uint32_t)data_intra-1;
	//cfg3              
	rc8088_userCfg->userDMA.e_jumpCnt    =0;
	rc8088_userCfg->userDMA.e_baseAddr   =0x1000;//0
	/*************************************************************************p10*/
	//cfg0 1
	if(rc8088_userCfg->zero_out_bypass){
		rc8088_userCfg->userP10.sw_timing_mode           =   1;
		rc8088_userCfg->userP10.sw_diff_mode             =   1;
		rc8088_userCfg->userP10.sw_timing_thres          =   0x7FFF;
		rc8088_userCfg->userP10.sw_diff_thres            =   0x7FFF;
	}
	switch(rc8088_userCfg->numRX-1){
			case 0: rc8088_userCfg->userP10.valid_ch_num = 0;break;
			case 1: rc8088_userCfg->userP10.valid_ch_num = 1;break;
			case 2: rc8088_userCfg->userP10.valid_ch_num = 2;break;
			case 3: rc8088_userCfg->userP10.valid_ch_num = 3;break;
			case 5: rc8088_userCfg->userP10.valid_ch_num = 2;break;
			case 7: rc8088_userCfg->userP10.valid_ch_num = 3;break;
	}
	rc8088_userCfg->userP10.timing_mul_fac = 0;
	rc8088_userCfg->userP10.diff_mul_fac = 0;
	rc8088_userCfg->userP10.dc_removal = rc8088_userCfg->dc_removal;
	rc8088_userCfg->userP10.zo_diff_mode = 2;
	rc8088_userCfg->userP10.zo_mode = 0;
	rc8088_userCfg->userP10.zo_zero_len = 3;
	/*************************************************************************fft*/
	//cfg0
	rc8088_userCfg->userFFT.win_sym = rc8088_userCfg->win_sym;
	rc8088_userCfg->userFFT.win_en = rc8088_userCfg->fftWinEn;
	rc8088_userCfg->userFFT.out_mode = rc8088_userCfg->fftOutMode;
	switch(rc8088_userCfg->fftNumPT){                                  // just for rookie, should be adjust by amplitude of signal
			case 2: rc8088_userCfg->userFFT.out_exp          =   3;break;  // 64
			case 3: rc8088_userCfg->userFFT.out_exp          =   4;break;  // 128
			case 4: rc8088_userCfg->userFFT.out_exp          =   5;break;  // 256
			case 5: rc8088_userCfg->userFFT.out_exp          =   6;break;  // 512
			case 6: rc8088_userCfg->userFFT.out_exp          =   7;break;  // 1024
			case 7: rc8088_userCfg->userFFT.out_exp          =   8;break;  // 2048
	}	
    rc8088_userCfg->userFFT.out_exp=15;
	rc8088_userCfg->userFFT.fftPt = readFFT_PT(rc8088_userCfg->fftNumPT);
	rc8088_userCfg->userFFT.mode = 0;
	//cfg1
	rc8088_userCfg->userFFT.outLsfEn = 0;
	rc8088_userCfg->userFFT.outSfb =0;
	rc8088_userCfg->userFFT.winLsfb = 0;
	/*************************************************************************mipi*/
	uint32_t    mipi_num        = 0;
	
	// switch(rc8088_userCfg->mipiCfg.Enable){
	// 	case 0:
	// 		rc8088_userCfg->userMipi.mipi0_en=1;
	// 		mipi_num=1;
	// 		break;
	// 	case 1:
	// 		rc8088_userCfg->userMipi.mipi1_en=1;
	// 		mipi_num=1;
	// 		break;
	// 	case 2:
	// 		rc8088_userCfg->userMipi.mipi0_en=1;
	// 		rc8088_userCfg->userMipi.mipi1_en=1;
	// 		mipi_num=2;
	// 		break;
	// }
	mipi_num=(rc8088_userCfg->mipiCfg.Enable&1)+((rc8088_userCfg->mipiCfg.Enable>>1)&1);
	rc8088_userCfg->userMipi.mipi0_en=rc8088_userCfg->mipiCfg.Enable&1;
	rc8088_userCfg->userMipi.mipi1_en=(rc8088_userCfg->mipiCfg.Enable>>1)&1;

	uint32_t    dma_b_bytes     = 0;
	if(rc8088_userCfg->fftEn){
			dma_b_bytes =  4 * (rc8088_userCfg->userDMA.b_intraCnt+1) * (rc8088_userCfg->userP10.valid_ch_num+1);
	}else{
			dma_b_bytes = 16 * (rc8088_userCfg->userDMA.b_intraCnt+1);
	}
	uint32_t    dma_d_bytes     = 0;
	if(rc8088_userCfg->fftEn && (rc8088_userCfg->numRX>3)){
			dma_d_bytes =  2 * (rc8088_userCfg->userDMA.d_intraCnt+1) * (rc8088_userCfg->userP10.valid_ch_num+1);
	}else{
			dma_d_bytes = 16 * (rc8088_userCfg->userDMA.d_intraCnt+1);
	}
	uint32_t    mipi_total_len  = (rc8088_userCfg->cpEn ? 16 : 0) +             // cp
																(dma_b_bytes) +                               // data
																(rc8088_userCfg->cqEn ? 96 : 0) +             // cq0, simplified, fixed
																(rc8088_userCfg->cqEn ? dma_d_bytes : 0);     // cq12
	//cfg0
	rc8088_userCfg->userMipi.mipi_crc_en = 1;
	rc8088_userCfg->userMipi.mipi_64bit_mode = 0;

	rc8088_userCfg->userMipi.mipi_dlane_mode=rc8088_userCfg->mipiCfg.DlaneMode+1;
	rc8088_userCfg->userMipi.mipi_data_type=rc8088_userCfg->mipiCfg.DataType;
	rc8088_userCfg->userMipi.mipi_wlevel=8-1;// 32-1;
	//cfg1
	if(rc8088_userCfg->fftEn){
	    switch(rc8088_userCfg->numRX-1){
	        case 0: rc8088_userCfg->userMipi.mipi_chirp_num=rc8088_userCfg->numMipiChirp;break;
	        case 1: rc8088_userCfg->userMipi.mipi_chirp_num=rc8088_userCfg->numMipiChirp;break;
	        case 2: rc8088_userCfg->userMipi.mipi_chirp_num=rc8088_userCfg->numMipiChirp;break;
	        case 3: rc8088_userCfg->userMipi.mipi_chirp_num=rc8088_userCfg->numMipiChirp;break;
	        case 5: rc8088_userCfg->userMipi.mipi_chirp_num=rc8088_userCfg->numMipiChirp<<1;break;
	        case 7: rc8088_userCfg->userMipi.mipi_chirp_num=rc8088_userCfg->numMipiChirp<<1;break;
		}	
	}else{
		rc8088_userCfg->userMipi.mipi_chirp_num=rc8088_userCfg->numMipiChirp;
	}
	rc8088_userCfg->userMipi.mipi_payload_len=mipi_total_len/mipi_num;
	//cfg2
	rc8088_userCfg->userMipi.mipi_head_cfg_en=0;
	rc8088_userCfg->userMipi.mipi_sf_head=0;
	//cfg3
	rc8088_userCfg->userMipi.mipi_ef_head=0;
	rc8088_userCfg->userMipi.mipi_sl_head=0;
	rc8088_userCfg->userMipi.mipi_el_head=0;
	rc8088_userCfg->userMipi.mipi_lp_head=0;
	//cfg4
	rc8088_userCfg->userMipi.mipi_tck_pre = rc8088_userCfg->mipiCfg.TckPre;
	rc8088_userCfg->userMipi.mipi_tck_zero = rc8088_userCfg->mipiCfg.TckZero;
	rc8088_userCfg->userMipi.mipi_tck_post = rc8088_userCfg->mipiCfg.TckPost;
	rc8088_userCfg->userMipi.mipi_tck_trail = rc8088_userCfg->mipiCfg.TckTrail;
	rc8088_userCfg->userMipi.mipi_tlpx = rc8088_userCfg->mipiCfg.Tlpx;//2;
	rc8088_userCfg->userMipi.mipi_ths_zero = rc8088_userCfg->mipiCfg.ThsZero;//8;
	rc8088_userCfg->userMipi.mipi_ths_trail = rc8088_userCfg->mipiCfg.ThsTrail;//3;
	//mem
	if (pCfg->SPI_RF_DEV == RC8088_RF_0)
	{
		rc8088_userCfg->userMemAddr.txpBuf_Addr=(RC8088_MemDat_st *)g_rf_far_userconfig.RC8088_TxpBuf;
	}
	else if (pCfg->SPI_RF_DEV == RC8088_RF_1)
	{
		rc8088_userCfg->userMemAddr.txpBuf_Addr=(RC8088_MemDat_st *)g_rf_near_userconfig.RC8088_TxpBuf;
	}
	else
	{
		printf("RC8088_userCfgDefault pCfg->SPI_RF_DEV err, SPI_RF_DEV is %u.\n", pCfg->SPI_RF_DEV);
		while(1);
	}
	rc8088_userCfg->userMemAddr.cBuf_Addr=(RC8088_MemDat_st *)m_profMemAddr->profileAddr;//zzg warnning 202501091424
}


















